#coding:utf-8
import time
from configparser import ConfigParser

import os
from Automation_frame.Runner.Actuator import runner
class continued(object):
    def __init__(self):
        self.cfg=ConfigParser()
        self.cfg.read('../test_data/ci.ini')
        self.data=self.cfg.items('woniusales_ui')

    def cmd_command(self):
        self.KeyLib_inte=KeyLib_inte()
        for cmd_data in self.data:
            method=cmd_data[0].split(' ')[0]
            func=getattr(self.KeyLib_inte,method)
            func(cmd_data[1])
    def begin(self):
        filepath=self.cfg.get('path','codedir')
        oldtime=os.path.getmtime(filepath)
        print(f'当前文件时间戳为{oldtime}')
        while True:
            newtime=os.path.getmtime(filepath)
            print(f'获取文件最新时间为{newtime}')
            if oldtime!=newtime:
                oldtime=newtime
                print('文件更新，开始部署环境')
                #部署环境
                self.cmd_command()
                #执行测试用例
                runner().begin()
            else:
                print('文件未更新')
            time.sleep(30)   #每二十秒检查一次
if __name__ == '__main__':

    continued().begin()
    # cfg=ConfigParser()
    # cfg.read(r'D:\Demo89Lear3\UI_frame\test_data\ci.ini')
    # data=cfg.items('woniusales_ui')
    # for i in data:
    #     print(i)